package com.wanpinghui.wphlibrary.model.business.bean;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tencent.connect.UserInfo;
import com.wanpinghui.wphlibrary.WPHSdk;
import com.wanpinghui.wphlibrary.model.base.bean.ImageBean;
import com.wanpinghui.wphlibrary.model.oauth.OAuthService;
import com.wanpinghui.wphlibrary.model.oauth.bean.UserBean;
import com.yunshl.yunshllibrary.utils.TextUtil;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import retrofit.callback.YRequestCallback;

/***
 * 功能描述:生意圈动态
 * 作者:qiujialiu
 * 时间:2018/1/23
 ***/

public class DynamicBean {
    /**
     * area_ids (string, optional): 可见地区ids ,
     area_names (string, optional): 可见地区names ,
     avatar (string, optional): 头像 ,
     bid_point (integer, optional): 消费的汇币 ,
     content (string, optional): 内容 ,
     created_at (integer, optional): 创建时间 ,
     deleted_at (integer, optional): 删除时间 ,
     engineer_quantity (integer, optional): 工程商总数 ,
     id (integer, optional): 动态主键 ,
     likeList (Array[动态点赞传输对象], optional): 点赞列表 ,
     pictureList (Array[string], optional): 图片列表 ,
     pictures (string, optional): 图片,json数组 ,
     replyList (Array[动态回复传输对象], optional): 评论列表 ,
     type (integer, optional): 类型:1本人/2朋友/3广告 ,
     updated_at (integer, optional): 更新时间 ,
     user_id (integer, optional): 发起人 ,
     user_nickname (integer, optional): 发起人昵称 ,
     visible_type (integer, optional): 可见类型:1好友可见/11仅自己可见/21全国可见/31部分可见
     */

    private String area_ids;
    private String area_names;
    private String avatar;
    private int bid_point;
    private String content;
    private long created_at;
    private long deleted_at;
    private int engineer_quantity;
    private int id;
    private List<ThumbUpBean> likeList;
    //private List<ContentImg> pictureList;
    private String pictures;
    private List<CommentBean> replyList;
    private int type;
    private long updated_at;
    private int user_id;
    private String user_nickname;
    private int visible_type;

    private List<ContentImg> imgs;

    public DynamicBean() {
    }

    public String getUserName() {
        return user_nickname;
    }

    public String getContent() {
        try {
            if (TextUtil.isNotEmpty(content)) {
                return URLDecoder.decode(content, "utf-8");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return content;
    }

    public void setReplyList(List<CommentBean> replyList) {
        this.replyList = replyList;
    }

    public void setLikeList(List<ThumbUpBean> likeList) {
        this.likeList = likeList;
    }

    /**
     * 获取点赞人数
     * @return
     */
    public int getThumbUpCount() {
        return likeList == null ? 0 : likeList.size();
    }

    public int getCommentCount() {
        return replyList == null ? 0 : replyList.size();
    }

    public String getAvatar() {
        return avatar;
    }

    public int getEngineer_quantity() {
        return engineer_quantity;
    }

    public int getType() {
        return type;
    }

    public int getVisible_type() {
        return visible_type;
    }

    public long getCreated_at() {
        return created_at;
    }

    public List<CommentBean> getReplyList() {
        return replyList;
    }

    public int getUser_id() {
        return user_id;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getArea_names() {
        return area_names;
    }

    public String getPictures() {
        return pictures;
    }

    public void setCreated_at(long created_at) {
        this.created_at = created_at;
    }

    public int getId() {
        return id;
    }

    public abstract class DynType{
        public static final int TYPE_OWN = 1;
        public static final int TYPE_FRIEDN = 2;
        public static final int TYPE_ADVEN = 3;
    }

    public DynamicBean(String avatar, String content, long created_at, List<ThumbUpBean> likeList, List<CommentBean> replyList, int type, String user_nickname) {
        this.avatar = avatar;
        this.content = content;
        this.created_at = created_at;
        this.likeList = likeList;
        this.replyList = replyList;
        this.type = type;
        this.user_nickname = user_nickname;
    }

    public String getThumbUpStr() {
        if (likeList != null && likeList.size() > 0) {
            StringBuilder stringBuilder = new StringBuilder();
            for (ThumbUpBean bean : likeList) {
                stringBuilder.append(bean.getUser_nickname()+"，");
            }
            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
            return stringBuilder.toString();
        }
        return "";
    }

    public boolean haveILike(int myId) {
        if (likeList != null && likeList.size() > 0) {
            for (ThumbUpBean bean : likeList) {
                if (bean.getUser_id() == myId) {
                    return true;
                }
            }
        }
        return false;
    }

    public List<ContentImg> getContentImgs() {
        if (imgs==null && TextUtil.isNotEmpty(pictures)) {
            imgs = new Gson().fromJson(pictures, new TypeToken<List<ContentImg>>(){}.getType());
        }
        return imgs;
    }

}
